﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace SHomeWorkshop.LunarSF.StudentInfosManager.Converters
{
    [ValueConversion(typeof(string), typeof(int))]
    public class AdmissionDateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return -1;
            if (string.IsNullOrWhiteSpace(value as string)) return -1;

            switch (value.ToString())
            {
                case "2011-09": return 0;
                case "2012-09": return 1;
                case "2013-09": return 2;
                case "2014-09": return 3;
                case "2015-09": return 4;
                case "2016-09": return 5;
                case "2017-09": return 6;
                case "2018-09": return 6;
                case "2019-09": return 6;
                    //TODO: 更改年份时，这里要跟随改变。
                    //  注意 BaseInfosInputer.xaml 第209行。
                    //case "2018-09": return 7;
                    //case "2019-09": return 8;
            }

            return -1;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int)
            {
                switch ((int)value)
                {
                    case 0: return "2011-09";
                    case 1: return "2012-09";
                    case 2: return "2013-09";
                    case 3: return "2014-09";
                    case 4: return "2015-09";
                    case 5: return "2016-09";
                    case 6: return "2017-09";
                    case 7: return "2018-09";
                    case 8: return "2019-09";
                        //TODO: 更改年份时，这里要跟随改变。
                        //  注意 BaseInfosInputer.xaml 第209行。
                        //case 7: return "2018-09";
                        //case 8: return "2019-09";
                }
            }

            return "";
        }

        private static AdmissionDateConverter converter = new AdmissionDateConverter();

        public static AdmissionDateConverter Instance
        {
            get { return converter; }
        }
    }
}
